﻿Imports System
Imports ImobWeb.Dominio
Imports Miron.FrameworkTeste
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports ImobWeb.Negoc
Imports Spring.Objects.Factory.Xml

<TestClass()> _
Public Class PessoaDal
    Inherits TesteTransacionalInjecaoDependenciaSpring

#Region " ConfigLocations "

    Protected Overrides ReadOnly Property ConfigLocations() As String()
        Get
            NamespaceParserRegistry.RegisterParser(GetType(Spring.Data.Config.DatabaseNamespaceParser))
            Return New [String]() {"assembly://Teste.ImobWeb/Teste.ImobWeb/AutoWired.xml"}
        End Get
    End Property

#End Region

    Private testContextInstance As TestContext
    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    ' You can use the following additional attributes as you write your tests:
    '
    ' Use ClassInitialize to run code before running the first test in the class
    ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    ' End Sub
    '
    ' Use ClassCleanup to run code after all tests in a class have run
    ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
    ' End Sub
    '
    ' Use TestInitialize to run code before running each test
    <TestInitialize()> Public Overloads Sub Initialize()
        MyBase.DefaultRollback = False
        MyBase.Initialize()
    End Sub
    '
    ' Use TestCleanup to run code after each test has run
    ' <TestCleanup()> Public Sub MyTestCleanup()
    ' End Sub
    '
#End Region

#Region "Particoes de Equivalencia"

    Public Const PARTICAO_PESSOA_FISICA As String = " Select IdPessoa from Pessoa Where Discriminator = 'PessoaFisica' "

#End Region

#Region "Classes Injetadas"

    Private _pessoaNegoc As IPessoaNegoc
    Public Property PessoaNegoc() As IPessoaNegoc
        Get
            Return _pessoaNegoc
        End Get
        Set(ByVal value As IPessoaNegoc)
            _pessoaNegoc = value
        End Set
    End Property

    Private _particaoEquivalencia As ParticaoEquivalencia
    Public Property ParticaoEquivalencia() As ParticaoEquivalencia
        Get
            _particaoEquivalencia = New ParticaoEquivalencia("BASE_IMOB")
            Return _particaoEquivalencia
        End Get
        Set(ByVal value As ParticaoEquivalencia)
            _particaoEquivalencia = value
        End Set
    End Property

#End Region

    <TestMethod()> _
    Public Sub BuscarPessoaPorId()

        Dim _pessoa As PessoaFisica
        Dim _idPessoa As Long

        _idPessoa = Me.ParticaoEquivalencia.LongArrayFromParticao(PARTICAO_PESSOA_FISICA, 1)(0)

        _pessoa = Me.PessoaNegoc.Buscar(_idPessoa)

        Assert.IsNotNull(_pessoa)

    End Sub

    <TestMethod()> _
    Public Sub SalvarPessoaFisica()

        Dim _pessoa As New PessoaFisica

        _pessoa.CPF = "123.456.789-10"
        _pessoa.Nome = "Nome"
        _pessoa.SobreNome = "Sobrenome"

        Me.PessoaNegoc.Salvar(_pessoa)

        Assert.IsNotNull(_pessoa)

    End Sub

End Class